package com.iwayin.web.action.personal;

import java.util.List;

import com.iwayin.core.bo.category.CategoryBO;
import com.iwayin.core.bo.follow.FollowBO;
import com.iwayin.core.bo.user.UserBO;
import com.iwayin.core.dataobject.CategoryDO;
import com.iwayin.core.dataobject.UserDO;
import com.iwayin.web.action.BaseAction;
import com.iwayin.web.common.AjaxResult;

public class PersonalAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7985432788222291160L;
	private UserDO user;
	private UserDO query;
	private String methodName="askList";
	private List<UserDO> userList;
	private AjaxResult ajaxResult;
	private UserBO userBO;
	private CategoryBO categoryBO;
	private List<CategoryDO> cates;
	private boolean login;
	private UserDO otherUser;
	private FollowBO followBO;
	/**
	 * @descriptions 个人主页
	 * @return
	 */
	public String personalHome() {
		UserDO loginUser = this.getLoginUser();
		if(loginUser == null){
			return "otherHome";
		}else{
			if(loginUser.getId().equals(otherUser.getId())){
				return "myHome";
			}else{
				return "otherHome";
			}
		}
	}
	
	/**
	 * @descriptions 我的主页
	 * @return
	 */
	public String myHome(){
		user = this.userBO.getUserById(this.getLoginUser().getId());
		cates = categoryBO.listCategory();
		return SUCCESS;
	}

	/**
	 * @descriptions 别人的主页
	 * @return
	 */
	public String otherHome(){
		cates = categoryBO.listCategory();//分类
		otherUser = this.userBO.getUserById(otherUser.getId());//用户
		UserDO loginUser = this.getLoginUser();//登录用户
		if(loginUser!=null){//已经登录
			login = true;
			user = userBO.getUserById(loginUser.getId());
			//判断关注关系
			otherUser.setFollow(followBO.checkFollow(loginUser.getId(), otherUser.getId()));
			//TODO 匹配分数
		}
		return SUCCESS;
	}
	
	public String userSetting(){
		user = this.userBO.getUserById(user.getId());
		return SUCCESS;
	}
	
	public UserDO getUser() {
		return user;
	}

	public void setUser(UserDO user) {
		this.user = user;
	}

	public UserDO getQuery() {
		return query;
	}

	public void setQuery(UserDO query) {
		this.query = query;
	}

	public List<UserDO> getUserList() {
		return userList;
	}

	public AjaxResult getAjaxResult() {
		return ajaxResult;
	}

	public void setUserBO(UserBO userBO) {
		this.userBO = userBO;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public void setCategoryBO(CategoryBO categoryBO) {
		this.categoryBO = categoryBO;
	}

	public List<CategoryDO> getCates() {
		return cates;
	}

	public boolean isLogin() {
		return login;
	}

	public UserDO getOtherUser() {
		return otherUser;
	}

	public void setOtherUser(UserDO otherUser) {
		this.otherUser = otherUser;
	}

	public void setFollowBO(FollowBO followBO) {
		this.followBO = followBO;
	}
	
}